home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWViews / Include / FWPopup.h < prev    next >
Encoding:
Text File  |  1996-04-25  |  4.7 KB  |  152 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPopup.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWPOPUP_H
  11. #define FWPOPUP_H
  12.  
  13. #ifndef FWCONTRL_H
  14. #include "FWContrl.h"
  15. #endif
  16.  
  17. #ifndef FWFONT_H
  18. #include "FWFont.h"
  19. #endif
  20.  
  21. #ifndef FWRUNTYP_H
  22. #include "FWRunTyp.h"
  23. #endif
  24.  
  25. #ifndef FWNOTIFR_H
  26. #include "FWNotifr.h"
  27. #endif
  28.  
  29. #ifndef FWSTRING_H
  30. #include "FWString.h"
  31. #endif
  32.  
  33. //========================================================================================
  34. //    Forward class declarations
  35. //========================================================================================
  36.  
  37. class FW_CViewContext;
  38.  
  39. //========================================================================================
  40. //    Popup styles
  41. //========================================================================================
  42.  
  43. typedef unsigned short FW_PopupMenuStyle;
  44.  
  45. // Note: on Macintosh you can use variant codes defined in <controls.h>:
  46. //        popupFixedWidth, popupVariableWidth, popupUseAddResMenu, popupUseWFont
  47.  
  48. //========================================================================================
  49. //    CLASS FW_CPopupMenu
  50. //========================================================================================
  51.  
  52. class FW_CPopupMenu : public FW_CNativeControl
  53. {
  54. // ----- Initialization/destruction
  55. public:
  56.     FW_DECLARE_CLASS
  57.     FW_DECLARE_AUTO(FW_CPopupMenu)
  58.  
  59.     FW_CPopupMenu(Environment* ev, 
  60.                    FW_CSuperView* container, ODID id,
  61.                    const FW_CRect& bounds,
  62.                    FW_ResourceId menuId,
  63.                    const FW_CString& label,
  64.                    short titleWidth = 0,
  65.                    short initialMenuItem = 1,
  66.                    FW_PopupMenuStyle popupVariation = 0,
  67.                    const FW_CFont& font = FW_kSystemFont12,
  68.                    long popupRefCon = 0);
  69.  
  70.     FW_CPopupMenu(Environment* ev);
  71.     virtual ~FW_CPopupMenu();
  72.  
  73. public:
  74.     // ----- Inherited API
  75.  
  76.     // FW_CNativeControl 
  77.     virtual void        ControlClicked(Environment *ev, FW_ControlValue value, ODFacet* facet);
  78.  
  79.     // Archiving
  80.     static void*        Create(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  81.     static void            Destroy(void* object, FW_ClassTypeConstant type);
  82.     virtual void        Flatten(Environment*ev, FW_CWritableStream& stream) const;
  83.     virtual void        InitializeFromStream(Environment*ev, FW_CReadableStream& stream);
  84.     
  85.     // ----- New API -----
  86.     void                GetMenuString(Environment* ev, FW_CString& str) const;
  87.     void                GetMenuString(Environment* ev, short index, FW_CString& str) const;
  88.     FW_PlatformHandle    GetPlatformMenuHandle() const;
  89.  
  90. protected:
  91.     // ----- Internal use only
  92.     virtual FW_Boolean     PrivSetValue(Environment* ev, FW_ControlValue value, ODFacet* facet);
  93.  
  94. private:
  95.     void                 Initialize(Environment* ev, FW_ResourceId menuId, 
  96.                             const FW_CString& title, short titleWidth, 
  97.                             short initialMenuItem, FW_PopupMenuStyle variation,
  98.                             const FW_CFont& font, long popupRefCon);
  99. };
  100.  
  101. //========================================================================================
  102. //    CLASS FW_CPopupMenuNotification
  103. //========================================================================================
  104.  
  105. class FW_CPopupMenuNotification : public FW_CControlNotification
  106. {
  107. public:
  108.     FW_DECLARE_CLASS
  109.     
  110.     FW_CPopupMenuNotification(FW_CPopupMenu* popup);
  111.     FW_CPopupMenuNotification(const FW_CPopupMenuNotification& other);
  112.     virtual    ~FW_CPopupMenuNotification();
  113.  
  114.     FW_CPopupMenuNotification&    operator=(const FW_CPopupMenuNotification& other);
  115.     
  116.     void                GetMenuString(Environment*ev, FW_CString& str) const;
  117.     short                GetMenuIndex(Environment*ev) const;
  118.     
  119. private:
  120.     short                fMenuIndex;        // index of item selected
  121.     FW_CString            fMenuString;    // string of item selected
  122. };
  123.  
  124. //========================================================================================
  125. //    inlines
  126. //========================================================================================
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    FW_CPopupMenu::GetMenuString
  130. //----------------------------------------------------------------------------------------
  131.  
  132. inline void    FW_CPopupMenu::GetMenuString(Environment* ev, FW_CString& str) const
  133. {
  134.     GetMenuString(ev, (short)GetValue(ev), str);
  135. }
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    FW_CPopupMenuNotification::GetMenuString
  139. //----------------------------------------------------------------------------------------
  140.  
  141. inline    void    FW_CPopupMenuNotification::GetMenuString(Environment*, FW_CString& str) const
  142. {
  143.     str = fMenuString;
  144. }
  145.  
  146. inline    short    FW_CPopupMenuNotification::GetMenuIndex(Environment*) const
  147. {
  148.     return fMenuIndex ;
  149. }
  150.  
  151. #endif
  152.